//
//  LJJGoodsThreeButtonView.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/18.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJGoodsThreeButtonView.h"

@interface LJJGoodsThreeButtonView ()

@property (strong, nonatomic) UIButton *buyCarButton;    /** 购物车 **/
@property (strong, nonatomic) UIButton *joinBuyCarButton;    /** 加入购物车 **/
@property (strong, nonatomic) UIButton *buyButton;    /** 立即购买 **/
@property (strong, nonatomic) UIImageView *backImageView;    /** 背景图 **/

@end

@implementation LJJGoodsThreeButtonView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.backImageView];
        [self addSubview:self.buyCarButton];
        [self addSubview:self.joinBuyCarButton];
        [self addSubview:self.buyButton];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    [_backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    [_buyCarButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(26 * FitWidth, 26 * FitHeight));
        make.left.equalTo(weakSelf.mas_left).offset(13 * FitWidth);
        make.centerY.equalTo(weakSelf.mas_centerY);
    }];
    [_joinBuyCarButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.height.equalTo(@70);
        make.left.equalTo(weakSelf.buyCarButton.mas_right).offset(35);
        make.right.equalTo(weakSelf.buyButton.mas_left).offset(30);
    }];
    [_buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.height.equalTo(@70);
        make.width.equalTo(weakSelf.joinBuyCarButton.mas_width);
        make.right.equalTo(weakSelf.mas_right).offset(-15);
    }];
}
- (void)addToBuyCar:(UIButton *)sender
{
    if (_block) {
        _block();
    }
}
#pragma mark -
#pragma mark - lazy method
- (UIButton *)buyCarButton
{
    if (!_buyCarButton) {
        _buyCarButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_buyCarButton setImage:[UIImage imageNamed:@"详情界面购物车按钮"] forState:UIControlStateNormal];
    }
    return _buyCarButton;
}
- (UIButton *)joinBuyCarButton
{
    if (!_joinBuyCarButton) {
        _joinBuyCarButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_joinBuyCarButton setImage:[UIImage imageNamed:@"详情界面加入购物车按钮"] forState:UIControlStateNormal];
        [_joinBuyCarButton addTarget:self action:@selector(addToBuyCar:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _joinBuyCarButton;
}
- (UIButton *)buyButton
{
    if (!_buyButton) {
        _buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_buyButton setImage:[UIImage imageNamed:@"详情界面立即购买按钮"] forState:UIControlStateNormal];
    }
    return _buyButton;
}
- (UIImageView *)backImageView
{
    if (!_backImageView) {
        _backImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabbar_back"]];
    }
    return _backImageView;
}

@end
